#include<bits/stdc++.h>
using namespace std;

int c, T, n, m, L, V, d[100005], v[100005], a[100005], p[100005], cnt, M;

int main () {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> T;
    while (T--) {
        cin >> n >> m >> L >> V;
        for (int i = 1; i <= n; i++) {
            cin >> d[i] >> v[i] >> a[i];
        }
        for (int i = 1; i <= m; i++) {
            cin >> M;
        }
        for (int i = 1; i <= n; i++) {
            if (v[i] > V && d[i] <= M) cnt++;
        }
        if (cnt == 0) c = m;
        else if (m == 1) c = 1;
        else if (m == 0) c = 0;
        else c = m - 1;
        cout << cnt << ' ' << c << '\n';
        cnt = 0;
    }
    return 0;
}
